#!/bin/bash

#Created by Cheng 2016-0218
#Version 1.0

if [ $# -lt 1 ]; then
	echo `date +"%Y-%m-%d %H:%M:%S"`  "Usage: <ROOMNO> <PASSWORD>"
	exit 1
fi

#DESTNODE=$1
ROOMNO=$1
PASSWORD=$2

SOURCEDATAPATH=/ftpdata/bsmp/data
WORKPATH=/ftpdata/bsmp/streamsdata/

while true
do

DATE=`date +%Y%m%d`
LOGFILE=${WORKPATH}log/scpdatamv_${ROOMNO}_${DATE}.log

SOURCEDIR=${SOURCEDATAPATH}/${DATE}/
#DESTDIR=${DESTNODE}:/ftpdata/bsmp/data/

FileNum=`ls ${SOURCEDIR}/*.gz -lR|grep "^-"|wc -l`

for tar in ${SOURCEDIR}/*${ROOMNO}* ;
do
	FileNum=`ls ${SOURCEDIR}/*${ROOMNO}*.gz -lR|grep "^-"|wc -l`
	echo "FileNum is $FileNum"
	NodeNum=$(( $FileNum % 3 + 1 ))
	echo "NodeNum is $NodeNum"
	DESTDIR=root@gd-gz-sx-dn-10${NodeNum}:/data02/data/
	 ./expect.sh $PASSWORD $tar $DESTDIR  | tee -a ${LOGFILE} 
	rm -rf $tar ;
done

#echo "./expect $PASSWORD $SOURCEDIR $DESTDIR"
#./expect.sh $PASSWORD $SOURCEDIR $DESTDIR


        #       echo 'sleep.....start'
                sleep 30
        #       echo 'sleep....end'
done
